const app = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    ordertype:'',
    orderTab:'',
    orderList:'',
    pageNum:1,
    userType: ''
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.setData({
      userType: wx.getStorageSync('userType'),
      ordertype: options.ordertype,
      orderTab: options.orderTab
    })
    this.orderList();

  },
  // 订单列表
  orderList:function(){
    var { pageNum, ordertype, orderTab, orderList , userType} = this.data
    var _this = this
    var url = ''
    wx.showLoading({
      title: '加载中',
    })
    var data = {
      type: orderTab,
      goods_status: '',
      service_status: '',
      page: pageNum,
      token: app.globalData.token
    }
    if (orderTab == 1){
      data.goods_status = ordertype
    }else{
      data.service_status = ordertype
    }

    if (userType == 1){
      url = app.globalData.baseUrl + 'user/myBuyGoods'
    }else{
      url = app.globalData.baseUrl + 'user/mySaleGoods'
    }
    wx.request({
      url: url,
      data: data,
      success(res) {
        wx.hideLoading()
        console.log(res)
        if (res.data.code == 1000) {
          _this.setData({
            orderList: [...orderList, ...res.data.data.data]
          })
        } else {
          wx.showToast({
            title: res.data.message,
            icon: 'none',
            duration: 2000
          })
        }
      }
    })
  },
  // 点击作品或服务列表
  shopList: function (e) {
    var { objectid,id } = e.currentTarget.dataset;
    if (objectid != undefined){
      wx.navigateTo({
        url: '/taskPage/pages/worksDetail/worksDetail?id=' + objectid + '&type=1',
      })
    }else{
      wx.navigateTo({
        url: '/taskPage/pages/hireDetail/hireDetail?id=' + id,
      })
    }
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
    var { pageNum } = this.data
    pageNum ++;
    this.setData({
      pageNum
    })
    this.orderList();
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})
